﻿using System.Data;

namespace DAL
{
    public class Materials_DAL : clsConnect
    {
        private static readonly clsConnect cls = new clsConnect();
        #region[Get-Data]
        public DataTable GetMaterials()
        {
            cls.CreateNewSqlCommand();
            return cls.GetData("sp_tb_Materials_Search");
        }
        public DataTable GetMaterialsDetail_Edit(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Materials_Id", id);
            return cls.GetData("sp_tb_Materials_Detail_Edit");
        }
        public static DataTable GetMaterialFillter(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Materials_Type_Id", id);
            return cls.GetData("sp_tb_Materials_Fillter");
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertMaterials(ET.Materials_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Unit_Id", data.Unit_Id);
            cls.AddParameter("@Materials_Type_Id", data.Materials_Type_Id);
            cls.AddParameter("@Materials_Alias", data.Materials_Alias);
            cls.AddParameter("@Materials_Name", data.Materials_Name);
            cls.AddParameter("@Materials_Tankage", data.Materials_Tankage);
            cls.AddParameter("@National_Id",data.National_Id);
            cls.AddParameter("@ID_Manufacturer", data.ID_Manufacturer);
            cls.AddParameter("@DateOfManufacture", data.DateOfManufacture);
            cls.AddParameter("@Note", data.Note);
            cls.AddParameter("@Price_Initially", data.Price_Initially);
            cls.AddParameter("@VAT", data.VAT);
            cls.AddParameter("@DayWarranty", data.DayWarranty);
            return cls.ExecuteNonQuery("sp_tb_Materials_Insert");
        }
        public bool UpdateMaterials(ET.Materials_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Materials_Id", data.Materials_Id);
            cls.AddParameter("@Unit_Id", data.Unit_Id);
            cls.AddParameter("@Materials_Type_Id", data.Materials_Type_Id);
            cls.AddParameter("@Materials_Alias", data.Materials_Alias);
            cls.AddParameter("@Materials_Name", data.Materials_Name);
            cls.AddParameter("@Materials_Tankage", data.Materials_Tankage);
            cls.AddParameter("@National_Id", data.National_Id);
            cls.AddParameter("@ID_Manufacturer", data.ID_Manufacturer);
            cls.AddParameter("@DateOfManufacture", data.DateOfManufacture);
            cls.AddParameter("@Note", data.Note);
            cls.AddParameter("@Price_Initially", data.Price_Initially);
            cls.AddParameter("@VAT", data.VAT);
            cls.AddParameter("@DayWarranty", data.DayWarranty);
            return cls.ExecuteNonQuery("sp_tb_Materials_Update");
        }
        public bool DeleteMaterials(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Materials_Id", id);
            cls.ExecuteNonQuery("sp_tb_Materials_Delete");
            return true;
        }
        #endregion

        #region[Search-Fillter]
        public DataTable Search(string keywords)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@KEYWORDS", keywords);
            return cls.GetData("sp_tb_Materials_Search");
        }
        #endregion
    }
}
